package com.neusoft.EYSystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neusoft.EYSystem.dao.ClientDAO;
import com.neusoft.EYSystem.dao.MealConfigDAO;
import com.neusoft.EYSystem.po.*;
import com.neusoft.EYSystem.service.MealConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mealConfig")
public class MealConfigController {
    @Autowired
    private MealConfigService mealConfigService;
    @Autowired
    private MealConfigDAO mealConfigDAO;
    @Autowired
    private ClientDAO clientDAO;
    //管理员端 膳食管理 查看客户膳食配置
    @GetMapping("/pageClientAndConfig")
    public PageResponseBean<List<ClientAndConfig>> pageClientAndConfig(Long cur, Long number, Client client) {
        return mealConfigService.pageClientAndConfig(cur, number, client);
    }

    // 管理员端 入住管理 客户膳食配置界面 确认按钮
    // 根据客户名添加
    @PostMapping("/addMealConfig")
    public ResponseBean<Integer> addMealConfig(MealConfig mealConfig,Client client) {
        ResponseBean<Integer> response = new ResponseBean<>();
        QueryWrapper<Client> clientQueryWrapper = new QueryWrapper<>();
        clientQueryWrapper.eq("name", client.getName());
        Client client1 = clientDAO.selectOne(clientQueryWrapper);
        mealConfig.setClientId(client1.getClientId());
        try {
            if(mealConfigDAO.insert(mealConfig) > 0){
                response.setStatus(200);
                response.setMsg("客户饮食配置添加成功");
                return response;
            }else {
                response.setStatus(400);
                response.setMsg("客户饮食配置添加失败，可能是数据不完整或重复");
            }
        } catch (Exception e) {
            response.setStatus(500);
            response.setMsg("客户饮食配置添加失败: " + e.getMessage());
        }
        return response;
    }

    @PostMapping("/deleteMealConfig")
    public ResponseBean<Integer> deleteMealConfig(MealConfig mealConfig) {
        return null;
    }

    @PostMapping("/updateMealConfig")
    public ResponseBean<String> updateMealConfig(MealConfig mealConfig) {
        return null;
    }
}
